public class Demo06 {
    public static void main(String[] args) {
        //定义一个变量接收相加的和
        int num = 0;
        int a = 0;
        for (int i = 1; i <= 101; i += 2) {

            a++;
            if (a % 2 == 1) {
                num = num + i;
            } else {
                num = num - i;
            }
        }
        System.out.println("1-3+5-7+9-…..101=" + num);//不要写在循环里面，不然会输出多行
    }
}
